<template>
      <div class="form-group" style="padding-right:30px;">
            <div class="row">
                  <div class="col-xs-12">
                        <span>指定企業</span>
                  </div>
            </div>
            <div class="row" style="margin-top:5px;">
                  <div class="col-xs-10" style="padding-right:0px;">
                        <select class="form-control input-sm" v-model="company">
                              <option v-for="(item ,index) in companyOptions" :key="index" :value="item.id">{{item.text}}</option>
                        </select>
                  </div>
                  <div class="col-xs-2" style="margin-top:7px;padding-left:0px;">
                        <mast :storeObj="mastObj.storeObj"
                              :goodsObj="mastObj.goodsObj"
                              v-on="$listeners"
                              :company="companyValue"
                        />
                  </div>
            </div>
            <div style="border-bottom:1px solid #dddddd;margin-top:10px;"></div>
      </div>
</template>

<script>
import mast from '@/components/mast.vue';
export default {
      name:'companyComponent',
      components:{
            mast
      },
      props:{
            mastObj:{
                  type:Object
            },
            companyValue:{
                  type:String
            },
            isfav:{
                  type:Object
            }
      },
      data:function(){
            return {
                  companyOptions:[],
                  getCompanyUrl:'/suntorylink/module/CGI/COMMON.KIGIYO.CGI',
                  company:this.companyValue
            };
      },
      watch:{
            company(){
                  this.$emit('update:companyValue',this.company);
                  if(this.isfav.company){
                        this.isfav.company = false;
                  }else{
                        if(this.mastObj.storeObj.type === 'company'){
                              this.mastObj.storeObj.value = '0000';
                        }
                        if(this.mastObj.goodsObj.type === 'company'){
                              this.mastObj.goodsObj.value = '0000';
                        }
                  }
            },
            companyValue(){
                  this.company = this.companyValue;
            }
      },
      inheritAttrs: false,
      created(){
            var vm = this;
            this.$http.post(this.getCompanyUrl)
                  .then(function(response){
                        vm.companyOptions = response.data;
                        global.companyOptions = response.data;
                        vm.$emit('update:companyValue',vm.companyOptions[0].id);
                  });
      }
};
</script>